#include <iostream>
#include <algorithm>
using namespace std;

typedef struct COW
{
    int w; //重量
    int s; //强壮程度
    int sum = w + s;
    bool operator<(struct COW w)
    {
        return sum < w.sum;
    }
    bool operator>(struct COW w)
    {
        return sum > w.sum;
    }
} cow;

const int N = 50010;
const int INF = 0x3f3f3f3f;

int n;
cow a[N];
int all = 0; //工具值，记录当前牛承受的压力
int res = -INF;

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i].w >> a[i].s;
        a[i].sum = a[i].w + a[i].s;
    }
    sort(a, a + n); //排好序
    for (int i = 0; i < n; ++i)
    {
        res = max(res, all - a[i].s); //计算当前牛的风险值
        all += a[i].w;
    }
    cout << res;
}